home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / pascal / pars7.exe / P7DEMO.PAS < prev    next >
Pascal/Delphi Source File  |  1993-02-12  |  2KB  |  68 lines

  1. program p7demo;
  2. {$M 30000,0,655360}
  3. {This is a demo program comparing speed of a parsed function versus
  4. the precompiled version. It's cheating a little, because f is programmed
  5. as a function, which is ever so slightly slower than a procedure. You
  6. can also observe how much slower protected mode is, when you can use it.}
  7. {$N+,E+} {change the type "float" in realtype.pas to be able to compile
  8.            in N- mode}
  9. uses dos,crt,pars7,realtype;
  10.  
  11. var s:string; r,rold,xmin,xmax,ymin,ymax,fmin,fmax,x,y:float;
  12.      i,j,n,m:integer;
  13.      hour1,minute1,second1,sec1001,
  14.      hour2,minute2,second2,sec1002:word;
  15.      elapsed1,elapsed2,start,ende:float;
  16.      ans:char;
  17.      error:boolean;
  18.      myfunc:pparse;
  19.  
  20. procedure wait;
  21. begin
  22.   repeat
  23.   until keypressed;
  24.   if readkey='*' then;
  25. end;
  26.  
  27.  
  28. function f(x,y,t:float):float;
  29. begin
  30.   f:=cos(4*x*y*(exp(-0.3*x*x)*sin(3*sin(3*x) - 4*cos(4*y)) +
  31.                2*exp(-0.5*y*y)*cos(5*sin(3*x) + 2*cos(4*y))));
  32. end;
  33.  
  34. begin
  35.   clrscr;
  36.   s:='cos(4*x*y*(exp(-0.3*x^2)*sin(3*sin(3*x)-4*cos(4*y))+2*exp(-0.5*y^2)*cos(5*sin(3*x)+2*cos(4*y))))';
  37.   writeln('f(x,y) = ',s);
  38.   myfunc:=new(pparse,init(s,true,error));
  39.   writeln;
  40.   writeln('Done parsing.');
  41.   writeln('Now the compiled function f is being used.');
  42.   gettime(hour1,minute1,second1,sec1001);
  43.   for i:=1 to 50 do
  44.     for j:=1 to 50 do
  45.       r:=f(i/10,j/10,0);
  46.   gettime(hour2,minute2,second2,sec1002);
  47.   start:=(hour1*60+minute1)*60+second1+sec1001/100;
  48.   ende:=(hour2*60+minute2)*60+second2+sec1002/100;
  49.   elapsed1:=ende-start;
  50.   writeln('time for 2500 calls: ',elapsed1:6:2,' seconds');
  51.   writeln('Press any key');
  52.   wait;
  53.   writeln('Now the parsed function f is being used');
  54.   gettime(hour1,minute1,second1,sec1001);
  55.   with myfunc^ do
  56.   for i:=1 to 50 do
  57.     for j:=1 to 50 do
  58.       f(i/10,j/10,0,r);
  59.   gettime(hour2,minute2,second2,sec1002);
  60.   start:=(hour1*60+minute1)*60+second1+sec1001/100;
  61.   ende:=(hour2*60+minute2)*60+second2+sec1002/100;
  62.   elapsed2:=ende-start;
  63.   writeln('time for 2500 calls: ',elapsed2:6:2,' seconds');
  64.   writeln('Press any key');
  65.   wait;
  66.   dispose(myfunc,done);
  67. end.
  68.